﻿@using Mvp.Library.Entities;
@model IList<RealEstateItem>

@{
	ViewBag.Title = "Real Estate Info";
}

@foreach (RealEstateItem.ItemType type in Enum.GetValues(typeof(RealEstateItem.ItemType)))
{
	<div class="post">
		<h2 class="title">
			@switch (type)
   {
	   case RealEstateItem.ItemType.ForLease:
					<text>Townhomes for lease</text>
		   break;
	   case RealEstateItem.ItemType.ForSale:
					<text>Townhomes for sale</text>
		   break;

   }
		</h2>
		<div class="entry">
			<table class="RealEstate" border="1" cellspacing="0" >
				<tbody>
					<tr>
						<th>Unit</th>
						<th>Bed/Bath</th>
						<th>Price</th>
						<th>Contact</th>
					</tr>
					@{
                       var items = this.Model.Where(r => r.Type == type);
                       if (items.Count() > 0)
                       {
	                        foreach (RealEstateItem rei in items)
	                        {
							    <tr>
								    <td nowrap="nowrap">@rei.UnitNumber</td>
								    <td nowrap="nowrap">@rei.NumberOfBedrooms / @rei.NumberOfBathrooms.ToString("0.#")</td>
								    <td nowrap="nowrap">@rei.Price.ToString("c")</td>
								    <td nowrap="nowrap" class="Contact">@rei.Contact</td>
							    </tr> 
                            }
                        }
                        else
                        {
							<tr>
								<td colspan="4">
									No units available
								</td>
							</tr>
                       }
					}
				</tbody>
			</table>
		</div>
	</div>
}

<script type="text/javascript">
	$(document).ready(function () {
		$("table.RealEstate tr:nth-child(even)").addClass("RealEstateRow");
		$("table.RealEstate tr:nth-child(odd)").addClass("RealEstateRowAlt"); 
	});
</script>